package com.crowdsourcing.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by smallRen on 2017/11/2.
 */
public class SecurityFilter implements Filter {
    private String excludePath;

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;


        Object user = request.getSession().getAttribute("user");
        String path = request.getServletPath();
        if (excludePath.indexOf(path) != -1) {
            filterChain.doFilter(servletRequest, servletResponse);
        } else {

            if (user == null) {
                filterChain.doFilter(servletRequest, servletResponse);
            } else {
                filterChain.doFilter(servletRequest, servletResponse);
            }
        }
    }

    @Override
    public void destroy() {

    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
}
